<?php

namespace app\logic\model;

use app\logic\viewModel\MusicUserView;
use think\Model;

class LogicModel extends Model
{
    protected $writer_field = ['id','writer_name','writer_head_img','fans_num'];
    function getFindById($id,$field='*'){
        return $this->field($field)->find($id);
    }


    /**
     *  根据Music获取作家
     * @param array $arr
     * @return array
     */
    public function getWriterByMusic(array $arr): array
    {
        $music_ids = array_column($arr,'music_id');
        $writer = MusicUserView::getWriterByMusicId($music_ids);
        foreach ($arr as &$val){
            $val['writer'] = $writer[$val['music_id']]??[];
        }
        unset($val);
        return $arr;
    }
    /*function getWriter(){

        $list = $list->toArray();

    }*/
}